Equitment = cc.Node.extend({
	equitment:null,
	runningAction:null,
	ctor:function(p){
		this._super();
		p.addChild(this, 8, TAG_EQUITMENT_NODE);
		this.init();
		this.initAction();
		this.showLight();
	},
	init : function(){		
		var equitment=new Button(this,8,TAG_EQUITMENT,"#equitment.png",this.callback,this);
		equitment.setPosition(cc.p(this.width*0.5,this.height*0.5));
		
		var lightning=new Button(equitment,8,TAG_LIGHT,"#lightning/lightning1.png",this.callback,this);
		lightning.setPosition(cc.p(equitment.width*0.825, equitment.height*0.755));
		
		var tube=new Button(this,7,TAG_TUBE,"#tube.png",this.callback,this);
		tube.setPosition(cc.p(equitment.width*0.35, -equitment.height*0.1));
		
		var line=new Button(tube,8,TAG_LINE,"#line.png",this.callback,this);
		line.setScale(0.13);
		line.setRotation(85);
		line.setPosition(cc.p(tube.width*0.98,tube.height*0.23));
		line.setVisible(false);
		
		var line1=new Button(tube,8,TAG_LINE1,"#line.png",this.callback,this);
		line1.setScale(0.3);
		line1.setPosition(cc.p(tube.width*0.28,tube.height*0.05));
		line1.setVisible(false);
	},
	showLine:function(){
		var tube=this.getChildByTag(TAG_TUBE);
		var line=tube.getChildByTag(TAG_LINE);
		line.setVisible(true);
		var move=cc.moveTo(1,cc.p(tube.width*0.53,tube.height*0.27))
		line.runAction(cc.sequence(move));
	},
	showLine1:function(){
		var tube=this.getChildByTag(TAG_TUBE);
		var line1=tube.getChildByTag(TAG_LINE1);
		line1.setVisible(true);
		var move=cc.moveTo(1,cc.p(tube.width*0.28,tube.height*0.985));
		line1.runAction(cc.sequence(move));
	},
	initAction:function(){
		var animFrames=[];
		for(var i=1;i<4;i++){
			var str="lightning/lightning"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation=new cc.Animation(animFrames,0.15);
		this.runningAction=cc.animate(animation).repeatForever();
		this.runningAction.retain();
	},
	showLight:function(){
		var equitment=this.getChildByTag(TAG_EQUITMENT);
		var lightning=equitment.getChildByTag(TAG_LIGHT);
		lightning.runAction(this.runningAction);
	},
	addBubble:function(){
		var equitment=this.getChildByTag(TAG_EQUITMENT);
		var bubble=new cc.Sprite("#bubble1.png");
		bubble.setTag(TAG_BUBBLE);
		bubble.setPosition(cc.p(equitment.width*this.randX(),equitment.height*0.08));
		equitment.addChild(bubble);
		var move=cc.moveBy(0.5, cc.p(0,20));
		var scale=cc.scaleBy(0.5,1.2);
		bubble.runAction(cc.sequence(cc.spawn(move,scale),cc.callFunc(function() {
			bubble.removeFromParent(true);
			this.addBubble();
		}, this)));
	},
	randX:function(){
		var x=[0.21,0.22,0.23,0.24,0.25,0.26,0.27];
		var X=x[Math.floor(Math.random()*7)];
		return X;
	},
	callback:function(p){
		var func=cc.callFunc(function() {
			gg.flow.next();
		},this);
		switch (p.getTag()) {
		case TAG_TUBE:
			p.runAction(cc.sequence(cc.callFunc(function() {
				this.showLine();
			},this),cc.delayTime(1),cc.callFunc(function() {
				this.showLine1();
			},this),func));
			break;
		default:
			break;
		}
	}
});